﻿using System;
using System.Web;

namespace SoftwareMonkeys.Scriptech.Web
{
	/// <summary>
	/// Used to redirect requests in a way that works on any platform.
	/// </summary>
	public static class Redirector
	{
		static public void Go(string path)
		{
			Go(path, false);
		}
		
		static public void Go(HttpContext context, string path, bool persistForm)
		{
			if (FrameworkChecker.IsMono)
				context.Server.Transfer(path, persistForm); // works in linux but not on windows .NET.
			else
				//context.Response.Redirect(path, true); // shows ugly urls in browser
				context.Server.Execute(path, persistForm);

			// other redirect approaches							
			//HttpContext.Current.Server.Execute(newPath, false); // doesn't seem to work on linux
			//HttpContext.Current.Response.Redirect(path); // works on windows .NET but not Mono/Linux	
		}
		
		static public void Go(string path, bool persistForm)
		{			
			Go(HttpContext.Current, path, persistForm);
		}
	}
}
